package com.fdb.efp.cus.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.fdb.efp.cus.service.dao.CusPrelistRiskInfoDao;
import com.fdb.efp.cus.service.domain.CusPrelistRiskInfo;
import com.fdb.efp.cus.service.domain.CusPrelistRiskInfoTmp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.efp.console.service.vo.BizParamCfgVO;
import com.fdb.efp.cus.service.facade.CusPrelistRiskInfoService;
import com.fdb.efp.cus.service.vo.CusPrelistRiskInfoVO;
import com.fdb.basic.framework.core.base.FrameworkService;

/**
 * <p>
 * 客户预授信名单风险信息的Service实现类
 * </p>
 * 
 * @author yusys
 * @createDate 2018-05-12 17:59:39
 */
@Service("cusPrelistRiskInfoService")
public class CusPrelistRiskInfoServiceImpl implements CusPrelistRiskInfoService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(CusPrelistRiskInfoServiceImpl.class);

	@Autowired
	private CusPrelistRiskInfoDao cusPrelistRiskInfoDao;
	private Map<String, BizParamCfgVO> pramMap;
	// 通过的名单
	private List<CusPrelistRiskInfoTmp> passList;
	// 未通过的名单
	private List<CusPrelistRiskInfoTmp> noPassList;

	@Override
	public int insertCusPrelistRiskInfo(CusPrelistRiskInfoVO inCusPrelistRiskInfoVo) {
		logger.debug("当前新增数据为：" + inCusPrelistRiskInfoVo.toString());
		int count = 0;
		try {
			CusPrelistRiskInfo cusPrelistRiskInfo = new CusPrelistRiskInfo();
			beanCopy(inCusPrelistRiskInfoVo, cusPrelistRiskInfo);
			count = cusPrelistRiskInfoDao.insertCusPrelistRiskInfo(cusPrelistRiskInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常！", e);
			count = -1;
		}
		logger.debug("当前新增数据条数为：" + count);
		return count;
	}

	@Override
	public int deleteByPk(CusPrelistRiskInfoVO inCusPrelistRiskInfoVo) {
		logger.debug("当前删除数据条件为：" + inCusPrelistRiskInfoVo.toString());
		int count = 0;
		try {
			CusPrelistRiskInfo cusPrelistRiskInfo = new CusPrelistRiskInfo();
			beanCopy(inCusPrelistRiskInfoVo, cusPrelistRiskInfo);
			count = cusPrelistRiskInfoDao.deleteByPk(cusPrelistRiskInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常！", e);
			count = -1;
		}
		logger.debug("根据条件：" + inCusPrelistRiskInfoVo + "删除的数据条数为" + count);
		return count;
	}

	@Override
	public int updateByPk(CusPrelistRiskInfoVO inCusPrelistRiskInfoVo) {
		logger.debug("当前修改数据为：" + inCusPrelistRiskInfoVo.toString());
		int count = 0;
		try {
			CusPrelistRiskInfo cusPrelistRiskInfo = new CusPrelistRiskInfo();
			beanCopy(inCusPrelistRiskInfoVo, cusPrelistRiskInfo);
			count = cusPrelistRiskInfoDao.updateByPk(cusPrelistRiskInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常！", e);
			count = -1;
		}
		logger.debug("根据条件：" + inCusPrelistRiskInfoVo + "修改的数据条数为" + count);
		return count;
	}

	@Override
	public CusPrelistRiskInfoVO queryByPk(CusPrelistRiskInfoVO inCusPrelistRiskInfoVo) {
		logger.debug("当前查询参数信息为：" + inCusPrelistRiskInfoVo);
		try {
			CusPrelistRiskInfo cusPrelistRiskInfo = new CusPrelistRiskInfo();
			beanCopy(inCusPrelistRiskInfoVo, cusPrelistRiskInfo);
			CusPrelistRiskInfo querycusPrelistRiskInfo = cusPrelistRiskInfoDao.queryByPk(cusPrelistRiskInfo);
			if (Objects.nonNull(querycusPrelistRiskInfo)) {
				CusPrelistRiskInfoVO outCusPrelistRiskInfoVo = beanCopy(querycusPrelistRiskInfo, new CusPrelistRiskInfoVO());
				logger.debug("当前查询结果为：" + outCusPrelistRiskInfoVo.toString());
				return outCusPrelistRiskInfoVo;
			} else {
				logger.debug("当前查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常！", e);
		}
		return null;
	}

	@Override
	public CusPrelistRiskInfoVO queryByCondition(CusPrelistRiskInfoVO inCusPrelistRiskInfoVo) {
		logger.debug("当前查询参数信息为：" + inCusPrelistRiskInfoVo);
		try {
			CusPrelistRiskInfo cusPrelistRiskInfo = new CusPrelistRiskInfo();
			beanCopy(inCusPrelistRiskInfoVo, cusPrelistRiskInfo);
			CusPrelistRiskInfo querycusPrelistRiskInfo = cusPrelistRiskInfoDao.queryByCondition(cusPrelistRiskInfo);
			if (Objects.nonNull(querycusPrelistRiskInfo)) {
				CusPrelistRiskInfoVO outCusPrelistRiskInfoVo = beanCopy(querycusPrelistRiskInfo, new CusPrelistRiskInfoVO());
				logger.debug("当前查询结果为：" + outCusPrelistRiskInfoVo.toString());
				return outCusPrelistRiskInfoVo;
			} else {
				logger.debug("当前查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常！", e);
		}
		return null;
	}

	/**
	 * 根据条件查询风险信息表,返回list
	 */
	@Override
	public List<CusPrelistRiskInfoVO> queryListByCondition(CusPrelistRiskInfoVO inCusPrelistRiskInfoVo) {
		logger.debug("当前查询参数信息为：" + inCusPrelistRiskInfoVo);
		List<CusPrelistRiskInfoVO> cpriv = new ArrayList<CusPrelistRiskInfoVO>();
		List<CusPrelistRiskInfo> cpri = new ArrayList<CusPrelistRiskInfo>();
		try {
			CusPrelistRiskInfo cusPrelistRiskInfo = new CusPrelistRiskInfo();
			beanCopy(inCusPrelistRiskInfoVo, cusPrelistRiskInfo);
			cpri = cusPrelistRiskInfoDao.queryListByCondition(cusPrelistRiskInfo);
			if (Objects.nonNull(cpri) && cpri.size() > 0) {
				for (CusPrelistRiskInfo cus : cpri) {
					CusPrelistRiskInfoVO info = new CusPrelistRiskInfoVO();
					beanCopy(cus, info);
					cpriv.add(info);
				}
				return cpriv;
			} else {
				logger.debug("当前查询结果为空！");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常！", e);
		}
		return null;
	}

	public Map<String, BizParamCfgVO> getPramMap() {
		return pramMap;
	}

	public void setPramMap(Map<String, BizParamCfgVO> pramMap) {
		this.pramMap = pramMap;
	}

	public List<CusPrelistRiskInfoTmp> getPassList() {
		return passList;
	}

	public void setPassList(List<CusPrelistRiskInfoTmp> passList) {
		this.passList = passList;
	}

	public List<CusPrelistRiskInfoTmp> getNoPassList() {
		return noPassList;
	}

	public void setNoPassList(List<CusPrelistRiskInfoTmp> noPassList) {
		this.noPassList = noPassList;
	}

}